# -*- coding: utf-8 -*-
import re
from common import get_from_yd
from common import sql_script
import set_cet6

def list2string(re_list):
    res = ""
    for i in re_list:
        if res:
            res += ";"
        res += i[0]
    return res

def get_gre():
    p=re.compile(r'\w+\.([^\.]+?)(\xef\xbc\x9b|\xef\xbc\x8c|$)')
    f = open('./gre.txt')
    i = 1
    allist = {}
    temp = []
    for line in f:
        if i%2:
            temp.append(line.strip())
            #get_from_yd.get_audio(line.strip(), "D:\Git\python-lite\gre")
        else:
            m = p.findall(line)
            if m:
                temp.append(list2string(m))
                allist[temp[0]]=temp[1]
                temp = []
            else:
                print i
        i += 1
    return allist

def main():
    cet4 = set_cet6.get_cet4().items()
    cet6 = set_cet6.get_cet6().items()
    gre = get_gre().items()
    sql_script.insert_list(cet4, "60.205.94.133", 48, "GRE词汇(1)", 3589)
    sql_script.insert_list(cet6, "60.205.94.133", 49, "GRE词汇(2)", 3912)
    sql_script.insert_list(gre, "60.205.94.133", 50, "GRE词汇(3)", 4061)
    print len(gre)
    #print len(cet4)
    #print len(cet6)
if __name__ == '__main__':
    main()
